#Include "Protheus.ch"

User Function CadMov()

Local aItens       := StrTokArr(RetVlrCBox("Z1_TPMOV"), ";")

Local bCancAct     := {|| oDlg:End()}
Local bOkAct       := {||}
Local bSelAct      := {|| cGetAnexo := cGetFile(cOpenMask, cOpenTit, 1, cOpenDir, lOpenSave, nConfig), oGetAnexo:Refresh()}
Local bOkWhen      := {|| !Empty(cGetCod) .AND. !Empty(cGetData) .AND. !Empty(cGetHist) .AND. !Empty(cGetNatur) .AND. !Empty(cGetValor) .AND. !Empty(cCBoxTpMov)}
Local bCancWhen    := {||}
Local bCodSetGet   := {|u| IF(PCount() > 0, cGetCod    := u, cGetCod   )}
Local bNomSetGet   := {|u| IF(PCount() > 0, cGetNome   := u, cGetNome  )}
Local bHisSetGet   := {|u| IF(PCount() > 0, cGetHist   := u, cGetHist  )}
Local bVlrSetGet   := {|u| IF(PCount() > 0, cGetValor  := u, cGetValor )}
Local bDtaSetGet   := {|u| IF(PCount() > 0, cGetData   := u, cGetData  )}
Local bNatSetGet   := {|u| IF(PCount() > 0, cGetNatur  := u, cGetNatur )}
Local bAnxSetGet   := {|u| IF(PCount() > 0, cGetAnexo  := u, cGetAnexo )}
Local bTMvSetGet   := {|u| IF(PCount() > 0, cCBoxTpMov := u, cCBoxTpMov)}
Local bCodValid    := {||}
Local bNomValid    := {||}
Local bHisValid    := {||}
Local bVlrValid    := {||}
Local bDtaValid    := {||}
Local bNatValid    := {||}
Local bAnxValid    := {||}
Local bTMvVal      := {||}
Local bCodWhen     := {||}
Local bNomWhen     := {||}
Local bHisWhen     := {||}
Local bVlrWhen     := {||}
Local bDtaWhen     := {||}
Local bNatWhen     := {||}
Local bAnxWhen     := {|| cCBoxTpMov == "P"}
Local bTMvWhen     := {||}
Local bSelWhen     := {|| cCBoxTpMov == "P"}
Local bCodChan     := {|| cGetNome := Posicione("SZ0", 1, xFilial("SZ0") + cGetCod, "Z0_NOME"), oGetNome:Refresh()}
Local bNomChan     := {||}
Local bHisChan     := {||}
Local bVlrChan     := {||}
Local bDtaChan     := {||}
Local bNatChan     := {||}
Local bAnxChan     := {||}
Local bTMvChan     := {||}
Local bDlgVal      := {||}
Local bDlgInit     := {||}

Local cOpenMask    := "Todos arquivos (*.*) | *.*"
Local cOpenTit     := "Selecione o arquivo"
Local cOpenDir     := "C:\"

Local lPixel       := .T.
Local lCentered    := .T.
Local lBold        := .T.
Local lUnderline   := .F.
Local lItalic      := .F.
Local lOpenSave    := .F.
Local lAnxReadOl   := .T.
Local lNomReadOl   := .T.

Local nConfig      := GETF_LOCALHARD + GETF_NETWORKDRIVE

Private cGetAnexo  := CriaVar("Z1_NOMANEX")
Private cGetCod    := CriaVar("Z1_CODIGO")
Private cGetData   := CriaVar("Z1_DATA")
Private cGetHist   := CriaVar("Z1_HISTORI")
Private cGetNatur  := CriaVar("Z1_NATUREZ")
Private cGetNome   := CriaVar("Z1_NOME")
Private cGetValor  := CriaVar("Z1_VALOR")
Private cCBoxTpMov := CriaVar("Z1_TPMOV")

Private oSans11B   := Nil
Private oDlg       := Nil
Private oSay1      := Nil
Private oSay2      := Nil
Private oSay3      := Nil
Private oSay4      := Nil
Private oSay5      := Nil
Private oSay6      := Nil
Private oSay7      := Nil
Private oSay8      := Nil
Private oGetCod    := Nil
Private oGetNome   := Nil
Private oGetValor  := Nil
Private oGetData   := Nil
Private oGetNatur  := Nil
Private oGetAnexo  := Nil
Private oCBoxTpMov := Nil
Private oSBtnOk    := Nil
Private oSBtnCanc  := Nil
Private oBtnSel    := Nil

oSans11B := TFont():New("MS Sans SerIF", Nil, -11, Nil, lBold, Nil, Nil, Nil, Nil, lUnderline, lItalic)

oDlg := MSDialog():New(089, 232, 527, 761, "Cadastro de Movimentos", Nil, Nil, Nil, Nil, /*nClrText*/, /*nClrBack*/, Nil, /*oWnd*/, lPixel, Nil, Nil, Nil, Nil, Nil)

	oSay1      := TSay():New(004, 004, {|| RetDescri("Z1_CODIGO") }, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay2      := TSay():New(028, 004, {|| RetDescri("Z1_NOME")   }, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay3      := TSay():New(052, 004, {|| RetDescri("Z1_TPMOV")  }, oDlg, , oSans11B, .F., .F., .F., .T., , , 040, 008)
	oSay4      := TSay():New(076, 004, {|| RetDescri("Z1_HISTORI")}, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay5      := TSay():New(100, 004, {|| RetDescri("Z1_VALOR")  }, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay6      := TSay():New(124, 004, {|| RetDescri("Z1_DATA")   }, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay7      := TSay():New(148, 004, {|| RetDescri("Z1_NATUREZ")}, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	oSay8      := TSay():New(172, 004, {|| RetDescri("Z1_NOMANEX")}, oDlg, , oSans11B, .F., .F., .F., .T., , , 032, 008)
	
	oGetCod    := TGet():New(012, 004, bCodSetGet, oDlg, 040, 008, X3Picture("Z1_CODIGO"), bCodValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bCodWhen, Nil, Nil, bCodChan, .F., .F., "SZ0", "cGetCod", Nil, Nil, Nil, Nil, Nil)
	oGetNome   := TGet():New(036, 004, bNomSetGet, oDlg, 248, 008, X3Picture("Z1_NOME"  ), bNomValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bNomWhen, Nil, Nil, bNomChan, lNomReadOl, .F., Nil, "cGetNome", Nil, Nil, Nil, Nil, Nil)
	oCBoxTpMov := TComboBox():New(060, 004, bTMvSetGet, aItens, 072, 010, oDlg, Nil, bTMvChan, bTMvVal, /*nClrBack*/, /*nClrText*/, lPixel, /*oFont*/, Nil, Nil, bTMvWhen, Nil, Nil, Nil, Nil, cCBoxTpMov)
	oGetHist   := TGet():New(084, 004, bHisSetGet, oDlg, 248, 008, X3Picture("Z1_HISTORI"), bHisValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bHisWhen, Nil, Nil, bHisChan, .F., .F., Nil, "cGetHist", Nil, Nil, Nil, Nil, Nil)
	oGetValor  := TGet():New(108, 004, bVlrSetGet, oDlg, 060, 008, X3Picture("Z1_VALOR")  , bVlrValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bVlrWhen, Nil, Nil, bVlrChan, .F., .F., Nil, "cGetValor", Nil, Nil, Nil, Nil, Nil)
	oGetData   := TGet():New(132, 004, bDtaSetGet, oDlg, 060, 008, X3Picture("Z1_DATA")   , bDtaValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bDtaWhen, Nil, Nil, bDtaChan, .F., .F., Nil, "cGetData", Nil, Nil, Nil, Nil, Nil)
	oGetNatur  := TGet():New(156, 004, bNatSetGet, oDlg, 060, 008, X3Picture("Z1_NATUREZ"), bNatValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bNatWhen, Nil, Nil, bNatChan, .F., .F., "SED", "cGetNatur", Nil, Nil, Nil, Nil, Nil)
	oGetAnexo  := TGet():New(180, 004, bAnxSetGet, oDlg, 208, 008, X3Picture("Z1_NOMANEX"), bAnxValid, /*nClrFore*/, /*nClrBack*/, /*oFont*/, Nil, Nil, lPixel, Nil, Nil, bAnxWhen, Nil, Nil, bAnxChan, lAnxReadOl, .F., Nil, "cGetAnexo", Nil, Nil, Nil, Nil, Nil)

	oBtnSel    := TButton():New(180, 216, "Selecionar...", oDlg, bSelAct, 037, 010, Nil, /*oFont*/, Nil, lPixel, Nil, Nil, Nil, bSelWhen, Nil, Nil)
	oSBtnOk    := SButton():New(196, 096, 1, bOkAct, oDlg, .T., "Confirmar", bOkWhen)
	oSBtnCanc  := SButton():New(196, 128, 2, bCancAct, oDlg, .T., "Cancelar", bCancWhen)

oDlg:Activate(Nil, Nil, Nil, lCentered, bDlgVal, Nil, bDlgInit, Nil, Nil)

Return Nil

// ---------------------------------------------------------------------------------------------- //

Static Function RetDescri(cCampo)

Local cDescri := ""

SX3->(dbSetOrder(2))

IF SX3->(dbSeek(cCampo))
	cDescri := X3Descric()
EndIF

Return cDescri

// ---------------------------------------------------------------------------------------------- //

Static Function RetVlrCBox(cCampo)

Local cVlrCBox := ""

SX3->(dbSetOrder(2))

IF SX3->(dbSeek(cCampo))
	cVlrCBox := X3CBOX()
EndIF

Return cVlrCBox

